/**
 * 将分钟转换为时刻字符串
 * @param minute
 */
export const minuteToTime = (minute: number): string => {
	const current = minute / 30 / 2;
	const ten = parseInt(String(current))
	if (ten < current) {
		return `${ten.toString().padStart(2, '0')}:30`
	}
	return `${current.toString().padStart(2, '0')}:00`
}

/**
 * 数组快排
 * @param arr
 */
export const quickSort = (arr: Array<number>): Array<number> => {
	if (arr.length <= 1) {
		return arr;
	}
	const pivotIndex = Math.floor(arr.length / 2);
	const pivot = arr.splice(pivotIndex, 1)[0];
	const left = [];
	const right = [];
	for (let i = 0; i < arr.length; i++) {
		if (arr[i] < pivot) {
			left.push(arr[i]);
		} else {
			right.push(arr[i]);
		}
	}
	return quickSort(left).concat([pivot], quickSort(right));
}

/**
 * 时间格式化
 */
export function formatDate(date: number): string {
	const hour: string = new Date(date).getHours().toString().padStart(2, '0')
	const minute: string = new Date(date).getMinutes().toString().padStart(2, '0')
	return hour + ":" + minute
}

/**
 * 对象深拷贝
 * @param value
 */
export function deepClone(value: any) {
	if(typeof value !== 'object' || value == null){
		return value
	}
	let result: any;
	if(value instanceof Array){
		result = []
	}else{
		result = {}
	}
	for(let key in value){
		if(value.hasOwnProperty(key)){
			result[key] = deepClone(value[key])// 递归
		}
	}
	return result;
}